/****************************************************************************
*
* Copyright (c) 2023  C*Core -   All Rights Reserved
*
* THIS SOFTWARE IS DISTRIBUTED "AS IS, " AND ALL WARRANTIES ARE DISCLAIMED,
* INCLUDING MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* PROJECT     : CCFC2011BC
* DESCRIPTION : CCFC2011BC FW demo code
* HISTORY     : Initial version.
* @file     demo.c
* @version  1.1
* @date     2023 - 02 - 20
* @brief    Initial version.
*
*****************************************************************************/
#include "demo.h"
#include "Mcu_lld.h"
#include "led_hw.h"
#include "console.h"
#include "intc_lld.h"
#include "sys.h"

/*******************************************************************************
 * @brief      LED_Test
 * @param[in]  None
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
static void LED_Test(void)
{
    LED_Set(LED2, LED_ON);
    delay_ms(500u);
    LED_Set(LED2, LED_OFF);
    delay_ms(500u);
}


/*******************************************************************************
 * @brief      Demo Test Function
 * @param[in]  None
 * @param[out] None
 * @retval     None
 * @notapi
 *******************************************************************************/
void Demo_Test(void)
{
#if ADC_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC ADC Demo:\n");
    ADC_Test_Demo();
#endif

#if FLASH_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC Flash Demo:\n");
    FLASH_Test_Demo();
#endif

#if IIC_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC IIC Demo:\n");
    IIC_Demo();
#endif

#if LINFLEX_DEMO_SW
    Lin_Demo();
#endif

#if PIT_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC PIT Demo:\n");
    PIT_TEST_Demo();
#endif

#if PWM_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC PWM Demo:\n");
    PWM_TEST_Demo();
#endif

#if RTCAPI_DEMO_SW
    INTC_IRQ_Enable(); /* Set the current priori */
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC RTC Demo:\n");
    RTCAPI_TEST_Demo();
#endif

#if STM_DEMO_SW
    //PSPRINTF("\n\n ARCH2D10_M1I1C2011BC STM Demo:\n");
    STM_TEST_Demo();
#endif

#if CAN_DEMO_SW
    //PSPRINTF("\n\n ARCH2D10_M1I1C2011BC CAN Demo:\n");
    //(void)CAN_TEST_Demo();
    hal_can_init_test();
#endif

#if CANFD_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC CANFD Demo:\n");
    (void)CANFD_TEST_Demo();
#endif

#if ICU_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC ICU Demo:\n");
    ICU_TEST_Demo();
#endif

#if SPI_DEMO_SW
    INTC_IRQ_Enable(); /* Set the current priori */
    //PSPRINTF("\n\n ARCH2D10_M1I1C2011BC SPI Demo:\n");
    Spi_Test_Demo();
#endif

#if INTC_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC INTC Demo:\n");
    INTC_CPR_Init(CPR_PRI_0);
    INTC_Test_Demo();
#endif

#if CORE_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC Core Demo:\n");
    (void)dhrystone_main(); /* PRQA S 3335*/
    (void)whetstone_main(); /* PRQA S 3335*/
    (void)coremark_main();  /* PRQA S 3335*/
#endif

#if ECSM_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC ECSM Demo:\n");
    ECSM_demo();
#endif

#if LOWPOWER_DEMO_SW
    #if LOWPOWER_STOP
    /* Stop mode */
    LowPower_Stop();
    while (ME_MODE_STOP == (ME.GS.R & ME_MODE_MASK))
    {
        ;
    }
    ME.RUN[0].R   = 0x001F0074u;
    Mcu_Apply_Mode(ME_MODE_RUN0);
    #else
    /* Standby mode */
    LowPower_Standby();
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    delay_ms(300u);
    #endif
#endif

#if SWT_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC SWT Demo:\n");
    SWT_TEST_Demo();
#endif

#if MPU_DEMO_SW
    PSPRINTF("\n\n ARCH2D10_M1I1C2011BC MPU Demo:\n");
    MPU_Test_Demo();
#endif

    //PSPRINTF("\n\n ARCH2D10_M1I1C2011BC Demo End!\n");
    //while (1)
    {
        LED_Test();
    }
}
